package socket

import (
	"common/mildware"
	"common/router"
	"common/websocket"
	"github.com/gin-gonic/gin"
	"project/pkg/dao/mysql"
	"project/pkg/dao/redis"
)

func init() {
	router.AddRouter(new(SRouter))
}

type SRouter struct {
}
type SHandler struct {
	M      mysql.Mysql
	R      redis.Redis
	socket *websocket.WebServerInfo
}

func NewSHandler() *SHandler {
	return &SHandler{
		socket: websocket.GetWebServer(),
		M:      mysql.NewMysql(),
		R:      redis.NewRedis(),
	}
}

// web socket
func (SRouter) Router(e *gin.Engine) {
	handler := NewSHandler()
	handler.socket.Server.OnConnection(handler.handleConnection)
	socket := e.Group("socket")
	socket.GET("/chat/people", handler.socket.Server.Handler())
	socket.POST("/friend/add", handler.AddFriend)
	socket.POST("/oldMsg/del", handler.delOldMsg)
	socket.Use(mildware.JWTAuthMiddleware())
	socket.POST("/friend/search", handler.SearchFriendPeople)
	socket.POST("/friend/del", handler.DelFriend)
}
